/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entities.BookTables;
import entities.Customers;
import entities.Restaurants;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author TANGQUOCTUAN
 */
@Stateless
public class BookTablesFacade extends AbstractFacade<BookTables> implements BookTablesFacadeLocal {

    @PersistenceContext(unitName = "eProject_Tunga_Restaurant-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public BookTablesFacade() {
        super(BookTables.class);
    }

    public List showBookTable() {
        Query r = em.createNamedQuery("BookTables.findAll");
        return r.getResultList();
    }

    public boolean insertbooktable(int noSeats, int resID, String custID, Date orderDate, BigDecimal reserveFee) {
        Restaurants r = em.find(Restaurants.class, resID);
        BookTables bt = new BookTables(noSeats, orderDate, reserveFee);
        Customers c = em.find(Customers.class, custID);
        bt.setRestaurants(r);
        bt.setCustomers(c);
        r.getBookTablesList();
        c.getBookTablesList();
        em.persist(bt);
        return true;

    }

    public List getResName() {
        Query r = em.createNamedQuery("BookTables.findAll");
        return r.getResultList();
    }

    public List<BookTables> showallbyID(String username) {
        List<BookTables> list = new ArrayList<BookTables>();
        Query r = em.createNamedQuery("BookTables.findByBookTableByUser");
        r.setParameter("custID", username);
        return list = r.getResultList();
    }

    public boolean updateTable(Integer id, boolean status) {
        BookTables br = em.find(BookTables.class, id);
        br.setStatus(status);
        em.persist(br);
        return true;
    }

    public List<BookTables> reportShowBookRoom(Date fromdate, Date todate) {
        List<BookTables> list = new ArrayList<BookTables>();
        Query r = em.createNamedQuery("BookTables.findReportBookTable");
        r.setParameter("fromdate", fromdate);
        r.setParameter("todate", todate);
        return list = r.getResultList();
    }
}
